package com.woniu.controller;

import com.woniu.entity.Book;
import com.woniu.entity.KillBook;
import com.woniu.service.SecKillService;
import com.woniu.util.ResponseData;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/seckill")
@AllArgsConstructor
public class SecKillController {
    private SecKillService secKillService;
    /**
     * 接收书籍信息，把该书籍插入秒杀表中
     * 并且写入redis中
     */
    @PostMapping("/addKillBook")
    public ResponseData<?> addKillBook(@RequestBody KillBook killBook){
        return secKillService.addKillBook(killBook);
    }

    @GetMapping("/queryKillBook")
    public ResponseData<?> queryKillBook(){
        return secKillService.queryKillBook();
    }

    @GetMapping("/queryDetail/{bookId}")
    public ResponseData<?> queryDetail(@PathVariable("bookId") Integer bookId){
        return secKillService.queryDetail(bookId);
    }
    @GetMapping("/startKill/{bookId}")
    public ResponseData<?> startKill(@PathVariable("bookId") Integer bookId){
        return secKillService.startKill(bookId);
    }
}
